package com.example.oneAgent;

import com.dynatrace.oneagent.sdk.OneAgentSDKFactory;
import com.dynatrace.oneagent.sdk.api.LoggingCallback;
import com.dynatrace.oneagent.sdk.api.OneAgentSDK;
import com.dynatrace.oneagent.sdk.api.OutgoingRemoteCallTracer;
import com.dynatrace.oneagent.sdk.api.enums.ChannelType;
import com.dynatrace.oneagent.sdk.api.infos.TraceContextInfo;
import org.springframework.stereotype.Component;

@Component
public class DynatraceProbe {

	private final OneAgentSDK							mvOneAgentSdk;

	public DynatraceProbe()
	{
		OneAgentSDK lvOneAgentSdk = null;
		try
		{
//			Class.forName("com.dynatrace.oneagent.sdk.OneAgentSDKFactory");
			lvOneAgentSdk = OneAgentSDKFactory.createInstance();
			System.out.println(lvOneAgentSdk.getTraceContextInfo());
			lvOneAgentSdk.setLoggingCallback(new LoggingCallback()
			{
				@Override
				public void warn(String pMessage)
				{
					System.out.println(pMessage);
				}

				@Override
				public void error(String pMessage)
				{
					System.out.println(pMessage);
				}
			});
			switch (lvOneAgentSdk.getCurrentState())
			{
				case ACTIVE:
					System.out.println("SDK is active and capturing.");
					break;
				case PERMANENTLY_INACTIVE:
					System.out.println("SDK is PERMANENTLY_INACTIVE; Probably no OneAgent injected or OneAgent is incompatible with SDK.");
					break;
				case TEMPORARILY_INACTIVE:
					System.out.println("SDK is TEMPORARILY_INACTIVE; OneAgent has been deactivated - check OneAgent configuration.");
					break;
				default:
					System.out.println("SDK is in unknown state.");
					break;
			}
		}
		catch (Exception e)
		{
			// ignored
			System.out.println(e);
		}
		finally
		{
			mvOneAgentSdk = lvOneAgentSdk;
		}
	}

	public String getMsgSeq()
	{
		OutgoingRemoteCallTracer lvOutgoingRemoteCall = mvOneAgentSdk.traceOutgoingRemoteCall("clientLogin", "wqew","DSASA", ChannelType.TCP_IP,"vm3014-itrade5.tx-tech.com");
		String lvTag = lvOutgoingRemoteCall.getDynatraceStringTag();
		System.out.println(lvTag);
		return lvTag;
	}

	public static void main(String[] args) {
		DynatraceProbe lvDynatraceProbe = new DynatraceProbe();
		System.out.println(lvDynatraceProbe.getMsgSeq());
	}

}
